package com.yygo.service;

import com.yygo.configentity.feedback.Role;
import com.yygo.configentity.feedback.RoleFeedback;
import com.yygo.configentity.feedback.RoleFeedbacks;
import com.yygo.util.RoleFeedbackConfigUtil;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by huanli on 2015/11/14.
 */
public class RoleFeedbacksConfigurer {
    private RoleFeedbacks roleFeedbacks;

    public RoleFeedback getRoleFeedbacks(String role, String phase) {
        List<Role> roleList = roleFeedbacks.getRoles().stream().filter((attachmentRole)-> attachmentRole.getName().equals(role)).collect(Collectors.toList());
        if (roleList.size()>0){
            List<RoleFeedback> retFeedbacks = roleList.get(0).getFeedbacks().stream().filter((roleFeedback) -> roleFeedback.getPhase().equals(phase)).collect(Collectors.toList());
            if (retFeedbacks.size()>0)
                return retFeedbacks.get(0);
        }
        return null;
    }

    public void init() {
        roleFeedbacks = new RoleFeedbackConfigUtil().read();
    }
}
